package validator;

import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import command.ConfirmationForm;

@Component
public class ConfirmationFormValidator implements Validator{

	@Override
	public boolean supports(Class<?> clazz) {
		return ConfirmationForm.class.equals(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		ConfirmationForm form = (ConfirmationForm) target;
		if(form.getCalification()==null){
			errors.rejectValue("calification", "empty");
		}
		if(form.getConfirmation()==null){
			errors.rejectValue("confirmation", "empty");
		}
		if(form.getComment().length()>255){
			errors.rejectValue("comment", "tooLong");
		}
	}

}
